from django.core.management.base import BaseCommand, CommandError
import os


def initialization():
    print("# [\033[1;33m 初始化数据 \033[0m] ...")
    if not os.path.exists("/opt/statics/media"):
        os.makedirs("/opt/statics/media/")
    if not os.path.exists("/opt/logs"):
        os.makedirs("/opt/logs/")
    # print("[\033[1;32m 初始化 \033[0m] iClouds.wsgi.initialize 全局配置...")


class Command(BaseCommand):
    help = "My custom startup command"

    def handle(self, *args, **kwargs):
        try:
            # put startup code here
            print("# [\033[1;32m 加载初始化数据 \033[0m] ...")
            # 清除缓存
            # clear_cache()
            # 启动脚本
            initialization()
        except:
            raise CommandError("Initalization failed.")
